package com.boc.client.filter;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

public class ErrorPage {
	private String defPage;
	private String waitTime;
	public ErrorPage(){
		defPage = "http://www.google.com";
		waitTime = "5";
	}
	public ErrorPage(String defPage,String waitTime){
		this.defPage = defPage;
		this.waitTime = waitTime;
	}
	public void writeErrorPage(HttpServletRequest request, ServletResponse response, String errMsg) throws IOException{
		response.setContentType("text/html;charset=GBK");
        PrintWriter out = response.getWriter();
        out.println("");
        out.println("<html>");
        out.println("<head>");
        out.println("<meta http-equiv=\"refresh\" content=\"" + waitTime + ";url=" + defPage + "\">");
        out.println("<meta http-equiv=\"pragma\" content=\"no-cache\">");
        out.println("<meta http-equiv=\"cache-control\" content=\"no-cache\">");
        out.println("<meta http-equiv=\"expires\" content=\"0\">");
        out.println("<script language=\"JavaScript\" type=\"text/JavaScript\">");
        out.println("<!--");
        out.println("var timenum = " + waitTime + ";");
        out.println("function errlink()");
        out.println("{");
        out.println("if(timenum == 0){");
        out.println("location.replace(\"" + defPage + "\")");
        out.println("}else{");
        out.println("timenum = timenum - 1;");
        out.println("timets.innerHTML = timenum + \" \u79D2\u949F\u540E\u5C06\u8F6C\u5165\u767B\u5F55\u9875\u9762\u3002\"");
        out.println("window.setTimeout( \"errlink()\", 1000 )");
        out.println("}");
        out.println("}");
        out.println("window.setTimeout( \"errlink()\", 1000 )");
        out.println("//-->");
        out.println("</script>");
        out.println("<style type=\"text/css\"><!--");
        out.println("a { text-decoration: none; color: #000080 }");
        out.println("A:visited {COLOR:#000000;TEXT-DECORATION:none }");
        out.println("a:hover { text-decoration: underline; COLOR: #ff0000}");
        out.println("body { scrollbar-base-color: #EBEBEB; scrollbar-arrow-color: #6A9DD0; font-size: 14px; background-image: url(" + defPage + "/images/default/bg.gif)}");
        out.println("table { font: 14px Tahoma, Verdana; color: #000000 }");
        out.println("input,select,textarea { font: 12px Tahoma, Verdana; color: #000000; font-weight: normal; background-color: #EBEBEB }");
        out.println("select { font: 12px Arial, Tahoma; color: #000000; font-weight: normal; background-color: #EBEBEB }");
        out.println(".nav { font: 14px Tahoma, Verdana; color: #000000; font-weight: bold }");
        out.println(".nav a { color: #000000 }");
        out.println(".header { font: 12px Tahoma, Verdana; color: #FFFFFF; font-weight: bold; background-image: url(" + defPage + "/images/default/headerbg.gif)}");
        out.println(".header a { color: #FFFFFF }");
        out.println(".category { font: 12px Arial, Tahoma; color: #000000; background-image: url(" + defPage + "/images/default/catbg.gif)}");
        out.println(".tableborder { background: #E6EEF7; border: 1px solid #6A9DD0 } ");
        out.println(".tableborder2 { background: #E6EEF7; border: 0px solid #6A9DD0 }");
        out.println(".tableborder3 { background: #E6EEF7; BORDER-RIGHT: #6A9DD0 1px solid; BORDER-LEFT: #6A9DD0 1px solid }");
        out.println(".singleborder { font-size: 0px; line-height: 1px; padding: 0px; background-color: #EBEBEB }");
        out.println(".smalltxt { font: 12px Arial, Tahoma }");
        out.println(".outertxt { font: 14px Tahoma, Verdana; color: #000000 }");
        out.println(".outertxt a { color: #000000 }");
        out.println(".bold { font-weight: bold }");
        out.println(".altbg1 { background: #EBEBEB }");
        out.println(".altbg2 { background: #FAFAFA }");
        out.println(".pub12blue {font-size: 12px; color: 23437E}");
        out.println(".f12blackno {font-size: 12px; color: #000000}");
        out.println(".yubaoqiwen { font-family: \"Times New Roman\", \"Times\", \"serif\"; font-size: 40px; font-weight: bolder; line-height: 40px; color: #000000; text-decoration: none; font-style: normal; font-variant: normal}");
        out.println(".citynameblack {font-family: \"\u9ED1\u4F53\"; font-size: 18px; font-weight: bold; line-height: 24px; color: #006699}");
        out.println(".cityname { font-size: 14px; font-weight: bold; line-height: 20px; color: #000000}");
        out.println(".pub12gray {  color: BCBCBC; font-size: 12px}");
        out.println(".pub12gray2 {  font-family: \"Arial\", \"Helvetica\", \"sans-serif\"; font-size: 12px; color: 9C9C9C}");
        out.println(".pub14blackb {  font-size: 14px; font-weight: bold; color: #000000}");
        out.println(".pub12white {color: #e7e7e7; font-size: 12px}");
        out.println(".lightblue {  font-size: 12px; color: #0066FF}");
        out.println(".MAX { font-size: 12px; font-weight: bolder; color: #FF6600}");
        out.println(".MIN { font-size: 12px; font-weight: bolder; color: #3366CC}");
        out.println("--></style>");
        out.println("</head>");
        out.println("<body>");
        out.println("<br><br><br><br><br><br><br><br><br><br><br><br>");
        out.println("<table cellspacing=\"1\" cellpadding=\"1\" width=\"50%\" align=\"center\" class=\"tableborder\">");
        out.println("<tr class=\"header\"><td>\u63D0\u793A\u4FE1\u606F</td></tr>");
        out.println("<tr><td class=\"altbg2\" align=\"center\">");
        out.println("<table border=\"0\" width=\"90%\" cellspacing=\"0\" cellpadding=\"0\">");
        out.println("<tr><td align=\"center\" class=\"smalltxt\">");
        out.println("<br>");
        out.println(errMsg);
        out.println("<br>");
        out.println("<br>");
        out.println("<div id=\"timets\">" + waitTime + " \u79D2\u949F\u540E\u5C06\u8F6C\u5165\u767B\u5F55\u9875\u9762\u3002</div>");
        out.println("<br><br>");
        out.println("<a href=\"" + defPage + "\">\u5982\u679C\u60A8\u7684\u6D4F\u89C8\u5668\u6CA1\u6709\u81EA\u52A8\u8DF3\u8F6C\uFF0C\u8BF7\u70B9\u51FB\u8FD9\u91CC</a>");
        out.println("<br><br>");
        out.println("</td></tr></table>");
        out.println("</td></tr></table>");
        out.println("</body>");
        out.println("</html>");

	}
}
